package person.bing.fbcloud.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: mengfanbing
 * @date: 2020/9/4 9:11
 */
public class Q257 {
    public static void main(String[] args) {

    }

    public List<String> binaryTreePaths(TreeNode root) {
        util(root,"");
        return ans;
    }
    private List<String> ans = new ArrayList<>();
    public void util(TreeNode node,String path) {
        if (node != null){
            if (!path.isEmpty()){
                path = path.concat("->");
            }
            path = path.concat(String.valueOf(node.val));
            if (node.left == null && node.right == null){
                ans.add(path);
                return;
            }
            util(node.left,path);
            util(node.right,path);
        }
    }

    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
}
